//
// DyneTK, the Dyne Toolkit
// Copyright (C) 2007 Matthias Melcher
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//

// generated by Fast Light User Interface Designer (fluid) version 1.0300

#include "Fldtk_Prefs.h"
Fldtk_Prefs_App::Fldtk_Prefs_App(int X, int Y, int W, int H, const char *L)
  : Fl_Group(0, 0, W, H, L) {
this->labelsize(12);
this->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
{ Fl_Check_Button* o = new Fl_Check_Button(15, 20, 205, 25, "Show the &Standard Toolbar");
  o->down_box(FL_DOWN_BOX);
  o->value(1);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
{ Fl_Check_Button* o = new Fl_Check_Button(15, 45, 205, 25, "Show the &Layout Toolbar");
  o->down_box(FL_DOWN_BOX);
  o->value(1);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
{ Fl_Check_Button* o = new Fl_Check_Button(15, 70, 205, 25, "Show the &Inspector Toolbar");
  o->down_box(FL_DOWN_BOX);
  o->value(1);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
{ Fl_Check_Button* o = new Fl_Check_Button(15, 95, 205, 25, "Show the S&tatus Toolbar");
  o->down_box(FL_DOWN_BOX);
  o->value(1);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
{ Fl_Box* o = new Fl_Box(230, 20, 155, 25, "All Toolbars:");
  o->labelsize(12);
  o->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  o->deactivate();
} // Fl_Box* o
{ Fl_Check_Button* o = new Fl_Check_Button(240, 45, 155, 25, "Show Tooltips");
  o->down_box(FL_DOWN_BOX);
  o->value(1);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
position(X, Y);
end();
}

Fl_Menu_Item Fldtk_Prefs_Layout::menu_Size[] = {
 {"Message Pad", 0,  0, 0, 1, FL_NORMAL_LABEL, 0, 12, 0},
 {"Message Pad 110...130", 0,  0, 0, 1, FL_NORMAL_LABEL, 0, 12, 0},
 {"Message Pad 2000", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {"Message Pad 2000 Landscape", 0,  0, 0, 1, FL_NORMAL_LABEL, 0, 12, 0},
 {"Custom", 0,  0, 0, 1, FL_NORMAL_LABEL, 0, 12, 0},
 {0,0,0,0,0,0,0,0,0}
};
Fldtk_Prefs_Layout::Fldtk_Prefs_Layout(int X, int Y, int W, int H, const char *L)
  : Fl_Group(0, 0, W, H, L) {
this->labelsize(12);
this->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
{ Fl_Check_Button* o = new Fl_Check_Button(20, 20, 75, 25, "&Grid On");
  o->down_box(FL_DOWN_BOX);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
{ Fl_Choice* o = new Fl_Choice(50, 50, 200, 20, "&Size:");
  o->down_box(FL_BORDER_BOX);
  o->labelsize(12);
  o->textsize(12);
  o->deactivate();
  o->menu(menu_Size);
} // Fl_Choice* o
{ Fl_Input* o = new Fl_Input(105, 110, 70, 20, "Height:");
  o->labelsize(12);
  o->textsize(12);
  o->deactivate();
} // Fl_Input* o
{ Fl_Input* o = new Fl_Input(260, 110, 70, 20, "Width");
  o->labelsize(12);
  o->textsize(12);
  o->deactivate();
} // Fl_Input* o
{ Fl_Input* o = new Fl_Input(375, 20, 45, 20, "Arrow Keys Move By:");
  o->type(2);
  o->labelsize(12);
  o->textsize(12);
  o->deactivate();
} // Fl_Input* o
{ Fl_Input* o = new Fl_Input(375, 50, 45, 20, "With Shift Key:");
  o->type(2);
  o->labelsize(12);
  o->textsize(12);
  o->deactivate();
} // Fl_Input* o
position(X, Y);
end();
}

Fl_Menu_Item Fldtk_Prefs_Browser::menu_Sort[] = {
 {"Hierarchy", 0,  0, 0, 1, FL_NORMAL_LABEL, 0, 12, 0},
 {"Name", 0,  0, 0, 1, FL_NORMAL_LABEL, 0, 12, 0},
 {0,0,0,0,0,0,0,0,0}
};

Fl_Menu_Item Fldtk_Prefs_Browser::menu_Sort1[] = {
 {"Name", 0,  0, 0, 1, FL_NORMAL_LABEL, 0, 12, 0},
 {"Type", 0,  0, 0, 1, FL_NORMAL_LABEL, 0, 12, 0},
 {0,0,0,0,0,0,0,0,0}
};
Fldtk_Prefs_Browser::Fldtk_Prefs_Browser(int X, int Y, int W, int H, const char *L)
  : Fl_Group(0, 0, W, H, L) {
this->labelsize(12);
this->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
{ Fl_Box* o = new Fl_Box(20, 15, 140, 25, "View List:");
  o->labelsize(12);
  o->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  o->deactivate();
} // Fl_Box* o
{ Fl_Box* o = new Fl_Box(20, 80, 140, 25, "Slot List:");
  o->labelsize(12);
  o->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  o->deactivate();
} // Fl_Box* o
{ Fl_Choice* o = new Fl_Choice(105, 45, 110, 20, "&Sort By:");
  o->down_box(FL_BORDER_BOX);
  o->labelsize(12);
  o->deactivate();
  o->menu(menu_Sort);
} // Fl_Choice* o
{ Fl_Choice* o = new Fl_Choice(105, 110, 110, 20, "&Sort By:");
  o->down_box(FL_BORDER_BOX);
  o->labelsize(12);
  o->deactivate();
  o->menu(menu_Sort1);
} // Fl_Choice* o
{ Fl_Button* o = new Fl_Button(245, 45, 75, 20, "&Font...");
  o->labelsize(12);
  o->deactivate();
} // Fl_Button* o
{ Fl_Button* o = new Fl_Button(245, 110, 75, 20, "&Font...");
  o->labelsize(12);
  o->deactivate();
} // Fl_Button* o
{ Fl_Check_Button* o = new Fl_Check_Button(130, 140, 140, 25, "Show Slot &Value");
  o->down_box(FL_DOWN_BOX);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
position(X, Y);
end();
}
Fldtk_Prefs_Text::Fldtk_Prefs_Text(int X, int Y, int W, int H, const char *L)
  : Fl_Group(0, 0, W, H, L) {
this->labelsize(12);
this->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
{ Fl_Check_Button* o = new Fl_Check_Button(20, 20, 95, 20, "Auto &Indent");
  o->down_box(FL_DOWN_BOX);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
{ Fl_Input* o = new Fl_Input(165, 21, 50, 18, "Tabs:");
  o->labelsize(12);
  o->textsize(12);
  o->deactivate();
} // Fl_Input* o
{ Fl_Button* o = new Fl_Button(245, 20, 75, 20, "&Font...");
  o->labelsize(12);
  o->deactivate();
} // Fl_Button* o
position(X, Y);
end();
}

void Fldtk_Prefs_Packages::cb_wPorttype_i(Fl_Choice* o, void*) {
  ((Fldtk_Prefs*)(o->window()))->set_changed();
}
void Fldtk_Prefs_Packages::cb_wPorttype(Fl_Choice* o, void* v) {
  ((Fldtk_Prefs_Packages*)(o->parent()))->cb_wPorttype_i(o,v);
}

Fl_Menu_Item Fldtk_Prefs_Packages::menu_wPorttype[] = {
 {"Serial", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {"Einstein", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {0,0,0,0,0,0,0,0,0}
};

void Fldtk_Prefs_Packages::cb_wPortname_i(Fl_Input_Choice* o, void*) {
  ((Fldtk_Prefs*)(o->window()))->set_changed();
}
void Fldtk_Prefs_Packages::cb_wPortname(Fl_Input_Choice* o, void* v) {
  ((Fldtk_Prefs_Packages*)(o->parent()))->cb_wPortname_i(o,v);
}

Fl_Menu_Item Fldtk_Prefs_Packages::menu_wPortnameWin32[] = {
 {"\\\\.\\COM1", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {"\\\\.\\COM2", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {"\\\\.\\COM3", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {"\\\\.\\COM4", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {0,0,0,0,0,0,0,0,0}
};

Fl_Menu_Item Fldtk_Prefs_Packages::menu_wPortnameUnix[] = {
 {"/dev/ttyS0", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {"/dev/ttyS1", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {"/dev/ttyS2", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {"/dev/ttyS3", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 12, 0},
 {0,0,0,0,0,0,0,0,0}
};
Fldtk_Prefs_Packages::Fldtk_Prefs_Packages(int X, int Y, int W, int H, const char *L)
  : Fl_Group(0, 0, W, H, L) {
this->labelsize(12);
this->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
portname_ = 0L;
porttype_ = 0;
{ Fl_Box* o = new Fl_Box(15, 15, 100, 25, "Connection");
  o->labelsize(12);
  o->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
} // Fl_Box* o
{ wPorttype = new Fl_Choice(85, 50, 100, 20, "&Type");
  wPorttype->down_box(FL_BORDER_BOX);
  wPorttype->labelsize(12);
  wPorttype->callback((Fl_Callback*)cb_wPorttype);
  wPorttype->menu(menu_wPorttype);
} // Fl_Choice* wPorttype
{ wPortname = new Fl_Input_Choice(240, 50, 165, 20, "Port:");
  wPortname->labelsize(12);
  wPortname->textsize(12);
  wPortname->callback((Fl_Callback*)cb_wPortname);
} // Fl_Input_Choice* wPortname
{ wPortnameWin32 = new Fl_Choice(240, 70, 100, 20);
  wPortnameWin32->down_box(FL_BORDER_BOX);
  wPortnameWin32->labelsize(12);
  wPortnameWin32->hide();
  wPortnameWin32->deactivate();
  wPortnameWin32->menu(menu_wPortnameWin32);
} // Fl_Choice* wPortnameWin32
{ wPortnameUnix = new Fl_Choice(240, 90, 100, 20);
  wPortnameUnix->down_box(FL_BORDER_BOX);
  wPortnameUnix->labelsize(12);
  wPortnameUnix->hide();
  wPortnameUnix->deactivate();
  wPortnameUnix->menu(menu_wPortnameUnix);
} // Fl_Choice* wPortnameUnix
// add the corrct pulldown menu
#ifdef WIN32
wPortname->menu(wPortnameWin32->menu());
#else
wPortname->menu(wPortnameUnix->menu());
#endif
{ Fl_Check_Button* o = new Fl_Check_Button(20, 90, 280, 25, "Auto &Save Before Building Package");
  o->down_box(FL_DOWN_BOX);
  o->value(1);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
{ Fl_Check_Button* o = new Fl_Check_Button(20, 115, 280, 25, "Auto &Download After Building Package");
  o->down_box(FL_DOWN_BOX);
  o->labelsize(12);
  o->deactivate();
} // Fl_Check_Button* o
position(X, Y);
end();
}

char * Fldtk_Prefs_Packages::port() {
  return portname_;
}

int Fldtk_Prefs_Packages::porttype() {
  return porttype_;
}

void Fldtk_Prefs_Packages::get_prefs(Fl_Preferences &prefs) {
  if (portname_)
  free(portname_);
  
#ifdef WIN32
  prefs.get("Portname", portname_, "\\\\.\\COM1");
#else
  prefs.get("Portname", portname_, "/dev/ttyS0");
#endif

prefs.get("Porttype", porttype_, 0);
}

void Fldtk_Prefs_Packages::set_prefs(Fl_Preferences &prefs) {
  prefs.set("Portname", portname_);
prefs.set("Porttype", porttype_);
}

void Fldtk_Prefs_Packages::update_data() {
  if (portname_)
  free(portname_);
portname_ = strdup(wPortname->value());
porttype_ = wPorttype->value();
}

void Fldtk_Prefs_Packages::update_dialog() {
  wPortname->value(portname_);
wPorttype->value(porttype_);
}
Fldtk_Prefs_Heaps::Fldtk_Prefs_Heaps(int X, int Y, int W, int H, const char *L)
  : Fl_Group(0, 0, W, H, L) {
this->labelsize(12);
this->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
{ Fl_Box* o = new Fl_Box(100, 15, 105, 25, "Size in KBytes");
  o->labelsize(12);
  o->deactivate();
} // Fl_Box* o
{ Fl_Input* o = new Fl_Input(90, 55, 90, 20, "Main Heap:");
  o->labelsize(12);
  o->textsize(12);
  o->deactivate();
} // Fl_Input* o
{ Fl_Input* o = new Fl_Input(275, 55, 90, 20, "Build Heap:");
  o->labelsize(12);
  o->textsize(12);
  o->deactivate();
} // Fl_Input* o
{ Fl_Box* o = new Fl_Box(35, 90, 280, 25, "Changes to Main Heap take effect after relaunching");
  o->labelsize(12);
  o->deactivate();
} // Fl_Box* o
position(X, Y);
end();
}

static void cb_Fldtk_Prefs(Fl_Double_Window* o, void*) {
  Fldtk_Prefs *w = (Fldtk_Prefs*)o;
w->hide();
w->update_dialog();
}

void Fldtk_Prefs::cb_wOK_i(Fl_Button*, void*) {
  update_data();
hide();
update_dialog();
set_prefs();
}
void Fldtk_Prefs::cb_wOK(Fl_Button* o, void* v) {
  ((Fldtk_Prefs*)(o->parent()))->cb_wOK_i(o,v);
}

void Fldtk_Prefs::cb_wCancel_i(Fl_Button*, void*) {
  hide();
update_dialog();
}
void Fldtk_Prefs::cb_wCancel(Fl_Button* o, void* v) {
  ((Fldtk_Prefs*)(o->parent()))->cb_wCancel_i(o,v);
}

void Fldtk_Prefs::cb_wApply_i(Fl_Button*, void*) {
  update_data();
update_dialog();
set_prefs();
}
void Fldtk_Prefs::cb_wApply(Fl_Button* o, void* v) {
  ((Fldtk_Prefs*)(o->parent()))->cb_wApply_i(o,v);
}
Fldtk_Prefs::Fldtk_Prefs(int X, int Y, int W, int H, const char *L)
  : Fl_Double_Window(X, Y, W, H, L) {
  _Fldtk_Prefs();
}

Fldtk_Prefs::Fldtk_Prefs(int W, int H, const char *L)
  : Fl_Double_Window(0, 0, W, H, L) {
  clear_flag(16);
  _Fldtk_Prefs();
}

void Fldtk_Prefs::_Fldtk_Prefs() {
this->box(FL_FLAT_BOX);
this->color(FL_BACKGROUND_COLOR);
this->selection_color(FL_BACKGROUND_COLOR);
this->labeltype(FL_NO_LABEL);
this->labelfont(0);
this->labelsize(14);
this->labelcolor(FL_FOREGROUND_COLOR);
this->callback((Fl_Callback*)cb_Fldtk_Prefs, (void*)(this));
this->align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE);
this->when(FL_WHEN_RELEASE);
{ Fl_Tabs* o = new Fl_Tabs(10, 10, 445, 210);
  o->labelsize(12);
  { app = new Fldtk_Prefs_App(10, 35, 445, 185, "App");
    app->box(FL_NO_BOX);
    app->color(FL_BACKGROUND_COLOR);
    app->selection_color(FL_BACKGROUND_COLOR);
    app->labeltype(FL_NORMAL_LABEL);
    app->labelfont(0);
    app->labelsize(12);
    app->labelcolor(FL_FOREGROUND_COLOR);
    app->align(FL_ALIGN_TOP);
    app->when(FL_WHEN_RELEASE);
    app->hide();
    app->deactivate();
    app->end();
  } // Fldtk_Prefs_App* app
  { layout = new Fldtk_Prefs_Layout(10, 35, 445, 185, "Layout");
    layout->box(FL_NO_BOX);
    layout->color(FL_BACKGROUND_COLOR);
    layout->selection_color(FL_BACKGROUND_COLOR);
    layout->labeltype(FL_NORMAL_LABEL);
    layout->labelfont(0);
    layout->labelsize(12);
    layout->labelcolor(FL_FOREGROUND_COLOR);
    layout->align(FL_ALIGN_TOP);
    layout->when(FL_WHEN_RELEASE);
    layout->hide();
    layout->deactivate();
    layout->end();
  } // Fldtk_Prefs_Layout* layout
  { browser = new Fldtk_Prefs_Browser(10, 35, 445, 185, "Browser");
    browser->box(FL_NO_BOX);
    browser->color(FL_BACKGROUND_COLOR);
    browser->selection_color(FL_BACKGROUND_COLOR);
    browser->labeltype(FL_NORMAL_LABEL);
    browser->labelfont(0);
    browser->labelsize(12);
    browser->labelcolor(FL_FOREGROUND_COLOR);
    browser->align(FL_ALIGN_TOP);
    browser->when(FL_WHEN_RELEASE);
    browser->hide();
    browser->deactivate();
    browser->end();
  } // Fldtk_Prefs_Browser* browser
  { text = new Fldtk_Prefs_Text(10, 35, 445, 185, "Text Views");
    text->box(FL_NO_BOX);
    text->color(FL_BACKGROUND_COLOR);
    text->selection_color(FL_BACKGROUND_COLOR);
    text->labeltype(FL_NORMAL_LABEL);
    text->labelfont(0);
    text->labelsize(12);
    text->labelcolor(FL_FOREGROUND_COLOR);
    text->align(FL_ALIGN_TOP);
    text->when(FL_WHEN_RELEASE);
    text->hide();
    text->deactivate();
    text->end();
  } // Fldtk_Prefs_Text* text
  { packages = new Fldtk_Prefs_Packages(10, 35, 445, 185, "Packages");
    packages->box(FL_NO_BOX);
    packages->color(FL_BACKGROUND_COLOR);
    packages->selection_color(FL_BACKGROUND_COLOR);
    packages->labeltype(FL_NORMAL_LABEL);
    packages->labelfont(0);
    packages->labelsize(12);
    packages->labelcolor(FL_FOREGROUND_COLOR);
    packages->align(FL_ALIGN_TOP);
    packages->when(FL_WHEN_RELEASE);
    packages->end();
  } // Fldtk_Prefs_Packages* packages
  { heaps = new Fldtk_Prefs_Heaps(10, 35, 445, 185, "Heaps");
    heaps->box(FL_NO_BOX);
    heaps->color(FL_BACKGROUND_COLOR);
    heaps->selection_color(FL_BACKGROUND_COLOR);
    heaps->labeltype(FL_NORMAL_LABEL);
    heaps->labelfont(0);
    heaps->labelsize(12);
    heaps->labelcolor(FL_FOREGROUND_COLOR);
    heaps->align(FL_ALIGN_TOP);
    heaps->when(FL_WHEN_RELEASE);
    heaps->hide();
    heaps->deactivate();
    heaps->end();
  } // Fldtk_Prefs_Heaps* heaps
  o->end();
} // Fl_Tabs* o
{ wOK = new Fl_Button(120, 235, 80, 25, "OK");
  wOK->labelsize(12);
  wOK->callback((Fl_Callback*)cb_wOK);
} // Fl_Button* wOK
{ wCancel = new Fl_Button(205, 235, 80, 25, "Cancel");
  wCancel->labelsize(12);
  wCancel->callback((Fl_Callback*)cb_wCancel);
} // Fl_Button* wCancel
{ wApply = new Fl_Button(290, 235, 80, 25, "&Apply");
  wApply->labelsize(12);
  wApply->callback((Fl_Callback*)cb_wApply);
} // Fl_Button* wApply
{ Fl_Button* o = new Fl_Button(375, 235, 80, 25, "&Help");
  o->labelsize(12);
  o->deactivate();
} // Fl_Button* o
get_prefs();
update_dialog();
set_modal();
end();
}

Fldtk_Prefs::Fldtk_Prefs(): Fl_Double_Window(470, 275) {
  _Fldtk_Prefs();
}

void Fldtk_Prefs::get_prefs() {
  int i;

Fl_Preferences prefs(Fl_Preferences::USER, "matthiasm.com", "DyneTK");

Fl_Preferences pack(prefs, "Packages");
packages->get_prefs(pack);

Fl_Preferences app(prefs, "Application");
app.get("win_x", win_x, 0xDECAFF);
app.get("win_y", win_y, 0xDECAFF);
app.get("win_w", win_w, 0xDECAFF);
app.get("win_h", win_h, 0xDECAFF);

Fl_Preferences pproj(prefs, "PreviousProjects");
pproj.get("n", nPrevProj, 0);
for (i=0; i<8; i++) 
    pproj.get(Fl_Preferences::Name(i), prevProj[i], "");
}

void Fldtk_Prefs::set_prefs() {
  int i;

Fl_Preferences prefs(Fl_Preferences::USER, "matthiasm.com", "DyneTK");
Fl_Preferences pack(prefs, "Packages");
packages->set_prefs(pack);

Fl_Preferences app(prefs, "Application");
app.set("win_x", win_x);
app.set("win_y", win_y);
app.set("win_w", win_w);
app.set("win_h", win_h);

Fl_Preferences pproj(prefs, "PreviousProjects");
pproj.set("n", nPrevProj);
for (i=0; i<8; i++) 
    pproj.set(Fl_Preferences::Name(i), prevProj[i]);
}

void Fldtk_Prefs::update_data() {
  packages->update_data();
}

void Fldtk_Prefs::update_dialog() {
  packages->update_dialog();
wOK->deactivate();
wApply->deactivate();
}

void Fldtk_Prefs::set_changed() {
  wOK->activate();
wApply->activate();
}

//
// DyneTK, the Dyne Toolkit
// Copyright (C) 2007 Matthias Melcher
//
